﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct st
{
	char name[20];
	int age;
};
int st_name(const void* p1, const void* p2)
{
	return strcmp(((struct st*)p1)->name, ((struct st*)p2)->name);
}
int st_age(const void* p1, const void* p2)
{
	return ((struct st*)p1)->age - ((struct st*)p2)->age;
}

void print_arr(struct st* arr, int sz)
{
	for (int i = 0; i < sz; i++)
	{
		printf("%s %d\n", arr[i].name, arr[i].age);
	}
}
int main()
{
	struct st arr[] = { {"zhangsan",20} ,{"lisi",31}, {"wangwu",27} };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), st_name);
	print_arr(arr, sz);
	qsort(arr, sz, sizeof(arr[0]), st_age);
	print_arr(arr, sz);
	return 0;
}
